package com.Bank;

import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

public class Method {
    static LinkedList<User> userList = new LinkedList<User>();
    Scanner scan = new Scanner(System.in);
    double mon;
    static int cardNum = 100000;
    static int Card = 0;

    void saveMon(int Card, int i) {
        /*存款方法
         * 传入账号Card，循环变量i
         *
         *
         *
         *
         *
         *
         *
         * */
        System.out.println("您的名字是" + userList.get(i).getName());
        System.out.println("请输入存款金额");
        try {
            mon = scan.nextDouble();
        } catch (InputMismatchException e) {
            e.printStackTrace();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        userList.get(i).setYuE(mon);
        System.out.println("存入" + mon + "元");
        System.out.println("现在您的账号余额" + userList.get(i).getYuE());

    }

    void getMon(int Card, int i) {
        /*取款方法
         * 传入账号Card，循环变量i
         *
         *
         *
         *
         *
         *
         *
         * */
        System.out.println("您的名字是" + userList.get(i).getName());
        System.out.println("请输入取款金额");
        try {
            mon = scan.nextDouble();
        } catch (InputMismatchException e) {
            e.printStackTrace();
        }
        if (mon < userList.get(i).getYuE()) {
            userList.get(i).setYuE2(mon);
            System.out.println("取出" + mon + "元");
            System.out.println("现在您的账号余额" + userList.get(i).getYuE());
        }

    }

    void cha(int Card, int i) {
        /*查询方法
         * 传入账号Card，循环变量i
         *
         *
         *
         *
         *
         *
         *
         * */
        System.out.println("您的名字是" + userList.get(i).getName());
        System.out.println("现在您的账号余额" + userList.get(i).getYuE());
    }

    void creatUser() {
        /*创建用户方法，因为取款机不提供该功能，因此仅调用一次做测试使用
         *
         *
         *
         *
         *
         *
         *
         * */
        String name = "";
        String miMa = "";
        System.out.println("请输入姓名");
        try {
            name = scan.next();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        System.out.println("请输入密码");
        try {
            miMa = scan.next();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        userList.add(new User(++cardNum, name, miMa));
        System.out.println("您的账号是:" + cardNum);
    }

    int dengLu() {       //登录方法，判断用户是否存在以及密码是否正确
        boolean tag = true;

        String miMa;
        System.out.println("请输入账号");
        try {
            Card = scan.nextInt();
        } catch (InputMismatchException e) {
            e.printStackTrace();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        System.out.println("请输入密码");
        miMa = scan.next();
        for (int i = 0; i < userList.size(); i++) {
            if (userList.get(i).hasNum(Card)) {
                if (userList.get(i).getMiMa().equals(miMa)) {
                    return i;
                } else {
                    System.out.println("密码错误");
                    break;
                }

            } else {

            }
        }

        System.out.println("查无此号");
        return -2;
    }
}

